﻿using Business.Base.Common;
using Business.Base.Enums;
using Business.Base.Model;
using Business.CentrifugalPump.Perf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Pumptester.ExperimentForms.CentrifugalPump.Perf
{
    public partial class CentrifugalPumpEditForm : Pumptester.ExperimentForms.Base.BaseEditForm
    {
        public CentrifugalPumpEditForm()
        {
            InitializeComponent();
        }

        public CentrifugalPumpEditForm(Experiment experiment):base(experiment)
        {
            InitializeComponent();
        }

        private void BandCombox()
        {
            Dictionary<ComboBox, DataSource[]> boxDic = new Dictionary<ComboBox, DataSource[]>();

            boxDic.Add(comboBoxFlowmeter, DataSource.DataSourceDic[DataSource.FLOWMETER]);
            boxDic.Add(comboBoxWindingConnection, DataSource.DataSourceDic[DataSource.WINDINGCONNECTION]);
            boxDic.Add(comboBoxWindingMaterial, DataSource.DataSourceDic[DataSource.WINGDINGMATERIAL]);
            boxDic.Add(comboBoxLevel, DataSource.DataSourceDic[DataSource.FLOWHEADLEVEL]);
            boxDic.Add(comboBoxRateVoltage, DataSource.DataSourceDic[DataSource.MOTORRATEDVOLTAGE]);

            foreach (KeyValuePair<ComboBox, DataSource[]> pair in boxDic)
            {
                pair.Key.DataSource = pair.Value;
                pair.Key.DisplayMember = "BindMember";
                pair.Key.ValueMember = "BindValue";
                pair.Key.SelectedIndex = 0;
            }

            //this.comboBoxPumpType.SelectedValue = pumpType;
        }

        private void CentrifugalPumpEditForm_Load(object sender, EventArgs e)
        {
            BandCombox();
            CentrifugalPumpPerfExperiment experiment = (CentrifugalPumpPerfExperiment)this.Experiment;
            this.textBoxCode.Text = experiment.ExperimentCode;
            this.textBoxPumpName.Text = experiment.PumpName;
            this.textBoxProductModel.Text = experiment.PumpModel;
            this.textBoxPumpCode.Text = experiment.PumpCode;
            this.textBoxExperimentOwner.Text = experiment.ExperimentOwner;
            this.textBoxManufacturer.Text = experiment.Manufacturer;

            this.textBoxRatedFlow.Text = experiment.PumpRatedFlow.ToString();
            this.textBoxRatedHead.Text = experiment.PumpRatedHead.ToString();
            this.textBoxRatedPower.Text = (experiment.PumpRatedPower).ToString();

            this.textBoxRatedSpeed.Text = experiment.MotorRatedSpeed.ToString();
     
            this.comboBoxRateVoltage.SelectedValue = ((int)experiment.MotorRatedVoltage);
            //this.textBoxRatedVoltage.Text = ((int)experiment.MotorRatedVoltage).ToString();

            this.textBoxRatedCurrent.Text = experiment.MotorRatedCurrent.ToString();
            this.textBoxRatedEff.Text = experiment.PumpRatedEfficiency.ToString();

            this.comboBoxWindingConnection.SelectedValue = experiment.MotorWindingConnection;
            //this.textBoxWindingConnection.Text = experiment.MotorWindingConnection;

            this.comboBoxWindingMaterial.SelectedValue = experiment.MotorWindingMaterial;
           //this.textBoxWindingMaterial.Text = experiment.MotorWindingMaterial;

            this.textBoxMotorEff.Text = experiment.MotorRatedEfficiency.ToString();
            this.textBoxImpellerDia.Text = (experiment.ImpellerDia * 1000).ToString();

            this.textBoxDInlet.Text = (experiment.DInlet * 1000).ToString();
            this.textBoxDOutlet.Text = (experiment.DOutlet * 1000).ToString();

            this.textBoxZInLet.Text = (experiment.ZInlet * 1000).ToString();
            this.textBoxZOutLet.Text = (experiment.ZOutlet * 1000).ToString();

            this.comboBoxFlowmeter.SelectedValue = experiment.FlowmeterAddress;
            //this.textBoxFlowmeter.Text = experiment.Flowmeter.ToString();

            this.textBoxCurrentTransRatio.Text = experiment.TransformationRatio.ToString();
            this.textBoxCustomer.Text = experiment.Customer;

            this.comboBoxLevel.SelectedValue = experiment.ExperimentLevel;
            //this.textBoxLevel.Text = ((int)experiment.ExperimentLevel) + "B";
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            CentrifugalPumpPerfExperiment experiment = (CentrifugalPumpPerfExperiment)this.Experiment;
            experiment.ExperimentCode = this.textBoxCode.Text;
            experiment.PumpName = this.textBoxPumpName.Text;
            //experiment.ExperimentName = this.textBoxPumpName.Text;
            experiment.PumpModel = this.textBoxProductModel.Text;
            experiment.PumpCode = this.textBoxPumpCode.Text;
            experiment.ExperimentOwner = this.textBoxExperimentOwner.Text;
            experiment.Manufacturer = this.textBoxManufacturer.Text;


            experiment.PumpRatedFlow = Convert.ToDouble(this.textBoxRatedFlow.Text);
            experiment.PumpRatedHead = Convert.ToDouble(this.textBoxRatedHead.Text);
            experiment.PumpRatedPower = Convert.ToDouble(this.textBoxRatedPower.Text);
            experiment.PumpRatedEfficiency = Convert.ToDouble(this.textBoxRatedEff.Text);

            //experiment.DesignStages = (int)Convert.ToInt32(this.textBoxImpellerDia.Text);
            experiment.MotorRatedSpeed = Convert.ToDouble(this.textBoxRatedSpeed.Text);
            //experiment.DesignSynchronousSpeed = Convert.ToDouble(this.textBoxSynchronousSpeed.Text);
            experiment.ImpellerDia = Convert.ToDouble(this.textBoxImpellerDia.Text) / 1000;
            experiment.MotorRatedVoltage = (MotorRatedVoltage)Convert.ToInt32(this.comboBoxRateVoltage.SelectedValue);
            experiment.MotorRatedCurrent = Convert.ToDouble(this.textBoxRatedCurrent.Text);
            //experiment.MotorRatedEfficiency = Convert.ToDouble(this.textBoxRatedEff.Text);
            experiment.MotorWindingConnection = (string)this.comboBoxWindingConnection.SelectedValue;
            experiment.MotorWindingMaterial = (String)this.comboBoxWindingMaterial.SelectedValue;

            experiment.MotorRatedEfficiency = Convert.ToDouble(this.textBoxMotorEff.Text);



            experiment.DInlet = Convert.ToDouble(this.textBoxDInlet.Text) / 1000;
            experiment.DOutlet = Convert.ToDouble(this.textBoxDOutlet.Text) / 1000;

            experiment.ZInlet = Convert.ToDouble(this.textBoxZInLet.Text) / 1000;
            experiment.ZOutlet = Convert.ToDouble(this.textBoxZOutLet.Text) / 1000;



            experiment.Flowmeter = comboBoxFlowmeter.Text;
            experiment.FlowmeterAddress = (int)comboBoxFlowmeter.SelectedValue;
            experiment.ExperimentType = ExperimentType.CentrifugalPumpPerf;
            experiment.ExperimentLevel = (FlowHeadLevel)this.comboBoxLevel.SelectedValue;
            experiment.CreateTime = DateTime.Now;
            //experiment.Flowmeter = this.comboBoxFlowmeter.SelectedText;
           // experiment.FlowmeterAddress = (int)this.comboBoxFlowmeter.SelectedValue;
            experiment.TransformationRatio = Convert.ToDouble(this.textBoxCurrentTransRatio.Text);
            //experiment.PumpType = pumpType;//普通离心泵
            experiment.Customer = this.textBoxCustomer.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
